package me.project.common.uitls.encrypt;

import java.security.MessageDigest;

public class MD5Utils {
    public static String MD5(String inStr) {
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
        inStr = "talkWorld"+inStr+"123";
        char[] charArray = inStr.toCharArray();
        byte[] byteArray = new byte[charArray.length];
	 
        for (int i = 0; i < charArray.length; i++)
            byteArray[i] = (byte) charArray[i];
        byte[] md5Bytes = md5.digest(byteArray);
        StringBuilder hexValue = new StringBuilder();
        for (byte md5Byte : md5Bytes) {
            int val = ((int) md5Byte) & 0xff;
            if (val < 16)
                hexValue.append("0");
            hexValue.append(Integer.toHexString(val));
        }
        return hexValue.toString();
 
    }

    public static boolean passwordIsTrue(String inputPassword,String md5DB) {
    	
    	String md5 = MD5(inputPassword);
    	return md5DB.equals(md5);
    }

    public static void main(String[] args) {
        String flyer = MD5Utils.MD5("flyer");
        System.out.println(flyer);
    }
 
}